<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="出库单" prop="outboundNo">
        <el-input
          v-model="queryParams.outboundNo"
          placeholder="请输入出库单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
		<el-form-item label="工单编号" prop="goodsstatus">
		  <el-select v-model="queryParams.goodsstatus" placeholder="请选择工单编号" clearable size="mini">
			<el-option v-for="dict in partnership_level" :key="dict.dictValue" :label="dict.dictLabel"
					   :value="dict.dictValue"/>
		  </el-select>
		</el-form-item>



		<el-form-item label="物料类别" prop="categoryName">
		  <el-select v-model="queryParams.categoryName" placeholder="请选择物料类别" clearable size="mini">
			<el-option v-for="item in gongdanList" :key="item.value" :label="item.categoryName"
					   :value="item.categoryName"/>
		  </el-select>
		</el-form-item>



    
		<el-form-item label="仓库" prop="warehouseName">
		  <el-select v-model="queryParams.warehouseName" placeholder="仓库名称" clearable size="mini">
			<el-option v-for="dict in partnership_level" :key="dict.dictValue" :label="dict.dictLabel"
					   :value="dict.dictValue"/>
		  </el-select>
		  <el-select v-model="queryParams.warehouseArea" placeholder="仓库区域" clearable size="mini">
			<el-option v-for="dict in partnership_level" :key="dict.dictValue" :label="dict.dictLabel"
					   :value="dict.dictValue"/>
		  </el-select>
		</el-form-item>
		<el-form-item label="领料人员" prop="pickingPerson">
		  <el-input
		    v-model="queryParams.pickingPerson"
		    clearable
		    @keyup.enter.native="handleQuery"
		  />
		</el-form-item>
		<el-form-item label="关联项目" prop="projectName">
		  <el-select v-model="queryParams.projectName" 
          placeholder="请选择关联项目" 
          clearable size="mini" 
          @change="selectrPoject">
			  <el-option v-for="item in guanxiangList" 
          :key="item.projectName" 
          :label="item.projectName"
					:value="item.projectNo"/>
		  </el-select>

		</el-form-item>
		<el-form-item label="出库人" prop="outboundPerson">
		  <el-input
		    v-model="queryParams.outboundPerson"
		    clearable
		    @keyup.enter.native="handleQuery"
		  />
		</el-form-item>
      <el-form-item label="出库时间">
        <el-date-picker
          v-model="daterangeOutboundTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['material:outboundOrder:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['material:outboundOrder:remove']"
        >批量删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['material:outboundOrder:export']"
        >导出</el-button>
      </el-col>
	  <el-col :span="1.5">
	    <el-button
	      type="success"
	      plain
	      icon="el-icon-edit"
	      size="mini"
	      :disabled="single"
	      @click="handlePrint"
	      v-hasPermi="['material:outboundOrder:edit']"
	    >打印</el-button>
	  </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="outboundOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="出库单号" align="center" prop="outboundNo" />
	  <el-table-column label="出库主题" align="center" prop="outboundTheme" />
      <el-table-column label="出库类型" align="center" prop="outboundType" />
	  <el-table-column label="出库时间" align="center" prop="outboundTime" >
	  <template slot-scope="scope">
	    <span>{{ parseTime(scope.row.outboundTime, '{y}-{m}-{d}') }}</span>
	  </template>     
	   </el-table-column>
	  <el-table-column label="物料摘要" align="center" prop="" />
	  <el-table-column label="仓库名称" align="center" prop="warehouseName" />
	  <el-table-column label="仓库区域" align="center" prop="warehouseArea" />
	  <el-table-column label="出库人员" align="center" prop="outboundPerson" />
	  <el-table-column label="本次出库数量" align="center" prop="" />
      <el-table-column label="关联生产订单编号" align="center" prop="orderNo" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
			<el-button
			  size="mini"
			  type="text"
			  icon="el-icon-edit"
			  @click="handleUpdate(scope.row)"
			  v-hasPermi="['material:outboundOrder:edit']"
			>编辑</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['material:outboundOrder:remove']"
          >删除</el-button>
		  <el-button
		    size="mini"
		    type="text"
		    icon="el-icon-edit"
		    @click="handleLook(scope.row)"
		    v-hasPermi="['material:outboundOrder:edit']"
		  >查看</el-button>
		  <el-button
		    size="mini"
		    type="text"
		    icon="el-icon-edit"
		    @click="handleConfirm(scope.row)"
		    v-hasPermi="['material:outboundOrder:edit']"
		  >确认出库</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    
  </div>
</template>

<script>
import { listOutboundOrder, getOutboundOrder,guanlianPro,wuliaoList, delOutboundOrder, addOutboundOrder, updateOutboundOrder,confirmOutOfStock, Querying } from "@/api/material/outboundOrder";
// import {  Querying} from "@/api/material/MaterialInfo";

export default {
  name: "OutboundOrder",
  dicts: ["binding_status", "partnership_level"],
  data() {
    return {
      // 关联项目下拉框
      guanxiangList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedMaterialInfo: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出库表格数据
      outboundOrderList: [],
      // 物料信息表格数据
      materialInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      gongdanList:[],
      daterangeOutboundTime: [],
      // 查询参数
      
      queryParams: {
        id:'',
        pageNum: 1,
        pageSize: 10,
        outboundNo: null,
        orderNo: null,
        projectNo: null,
        warehouseName: null,
        warehouseArea: null,
        outboundPerson: null,
        outboundTime: null,
        pickingPerson: null,
        categoryName:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
   
    wuliaoList(this.queryParams).then(res=>{
      for(let i = 0;i<res.rows.length;i++){
        this.gongdanList = res.rows[i].categoryName
        this.gongdanList = res.rows
      }
      // this.wuliaoList = res.rows.categoryName
      // console.log(res,"qqqqqqq")
    })
    guanlianPro(this.queryParams).then(res=>{
      for(let i = 0;i<res.rows.length;i++){
        this.guanxiangList = res.rows[i].projectName
        this.guanxiangList = res.rows
      }
      // this.wuliaoList = res.rows.categoryName
      // console.log(res,"qqqqqqq")
    })
    this.getList();
  },
  methods: {
    selectrPoject(projectNo){
      this.queryParams.projectNo=projectNo;
    },
    /** 查询出库列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeOutboundTime && '' != this.daterangeOutboundTime) {
        this.queryParams.params["beginOutboundTime"] = this.daterangeOutboundTime[0];
        this.queryParams.params["endOutboundTime"] = this.daterangeOutboundTime[1];
      }
      listOutboundOrder(this.queryParams).then(response => {
        this.outboundOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        outboundNo: null,
        outboundType: null,
        orderNo: null,
        projectNo: null,
        warehouseName: null,
        warehouseArea: null,
        outboundTheme: null,
        outboundPerson: null,
        outboundTime: null,
        pickingPerson: null,
        createTime: null,
        createBy: null,
        status: "0",
        comment: null,
        categoryName: null,
      };
      this.materialInfoList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeOutboundTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
		this.$router.push('/MaterialInfo/outboundOrderAdd')
      this.reset();
      this.open = true;
      this.title = "添加出库";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // const id = row.id || this.ids
      // getOutboundOrder(id).then(response => {
      //   this.form = response.data;
      //   this.materialInfoList = response.data.materialInfoList;
      //   this.open = true;
      //   this.title = "修改出库";
        
      // });
      
      this.$router.push({path:'/MaterialInfo/outboundOrderX',query:{id:row.id}})
    },
	handleLook(row){
    Querying(row.id).then((response) => {
        console.log(response,123132131)
        this.queryParams.createBy =  res.data.createBy
      })
		this.$router.push({path:'/MaterialInfo/outboundOrderLook',query:{id:row.id}})
	},
	//确认出库
	handleConfirm(row){
		confirmOutOfStock(row.id).then(res => {
      console.log(res)
		   this.getList();
		 });
	},
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.materialInfoList = this.materialInfoList;
          if (this.form.id != null) {
            updateOutboundOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOutboundOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除出库编号为"' + ids + '"的数据项？').then(function() {
        return delOutboundOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 物料信息序号 */
    rowMaterialInfoIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 物料信息添加按钮操作 */
    handleAddMaterialInfo() {
      let obj = {};
      obj.projectNo = "";
      obj.materialNo = "";
      obj.materialName = "";
      obj.materialType = "";
      obj.specifications = "";
      obj.unit = "";
      obj.count = "";
      obj.comment = "";
      this.materialInfoList.push(obj);
    },
    /** 物料信息删除按钮操作 */
    handleDeleteMaterialInfo() {
      if (this.checkedMaterialInfo.length == 0) {
        this.$modal.msgError("请先选择要删除的物料信息数据");
      } else {
        const materialInfoList = this.materialInfoList;
        const checkedMaterialInfo = this.checkedMaterialInfo;
        this.materialInfoList = materialInfoList.filter(function(item) {
          return checkedMaterialInfo.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleMaterialInfoSelectionChange(selection) {
      this.checkedMaterialInfo = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('material/outboundOrder/export', {
        ...this.queryParams
      }, `outboundOrder_${new Date().getTime()}.xlsx`)
    },
		handlePrint(){
			
		}
  }
};
</script>
